#include<iostream>
#include<map>
using namespace std;

int main() {
    map<int, int> m;
    int x;
    cin >> x;
    for (int i=0; i < x; i++) {
        int a, b;
        cin >> a >> b;
        m.insert(pair<int, int>(b, a));
    }
    for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
        cout << it->second << " " << it->first << endl;
    }


    return 0;
}